package com.zqweb.yuanxiaoTea.controller;

import com.alibaba.fastjson.JSON;
import com.zqweb.yuanxiaoTea.pojo.StudentEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 功能描述
 */
@RestController
@RequestMapping("/testReq")
@Api(value = "文档测试接口Controller")
@Slf4j
public class TestController {
    @GetMapping("/test/{id}")
    @ApiOperation(value = "测试方法1")
    @ApiImplicitParam(name = "id",value = "请求的id",required = true,dataTypeClass = Long.class)
    public String test1(@PathVariable("id") Long id){
        log.info("请求" + id + "到来啦！");
        return "这是测试" + id + "的响应内容！";
    }

    @PostMapping("/test/student")
    @ApiOperation(value = "测试方法2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "学生id",required = true,dataTypeClass = Long.class),
            @ApiImplicitParam(name = "name",value = "学生name",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "age",value = "学生age",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "sex",value = "学生sex",required = true,dataTypeClass = char.class),
            @ApiImplicitParam(name = "interests",value = "学生interests",required = false,dataTypeClass = String.class),
    })
    public String test2(StudentEntity studentEntity){
        log.info("学生信息为：" + studentEntity);
        String respStr = JSON.toJSONString(studentEntity);// 为null的属性，默认不构成JSON串的响应部分
        System.out.println("respStr = " + respStr);
        return respStr;
    }
}
